<template>
    <div class="app-container">
      <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="88px">
        <el-form-item label="产品编号" prop="materialCode">
          <el-input v-model="queryParams.materialCode" placeholder="请输入产品编号" clearable @keyup.enter.native="handleQuery" />
        </el-form-item>
        <el-form-item>
          <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
          <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
        </el-form-item>
      </el-form>

      <el-table v-loading="loading" :data="shipmentsList">
        <el-table-column type="selection" width="55" align="center" />
        <!-- <el-table-column label="出库Id" align="center" prop="shipmentsId" /> -->
        <el-table-column label="出库编号" align="center" prop="shipmentsCode" />
        <el-table-column label="出库时间" align="center" prop="shipmentsDate" width="180">
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.shipmentsDate, '{y}-{m}-{d} {h}:{i}:{s}') }}</span>
          </template>
        </el-table-column>
        <el-table-column label="代理商编号" align="center" prop="agentCode" />
        <el-table-column label="代理商名称" align="center" prop="agentName" />
        <el-table-column label="产品编号" align="center" prop="materialCode" />
        <el-table-column label="产品名称" align="center" prop="materialName" />
      </el-table>
      <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
        @pagination="getList" />
    </div>
  </template>
  
  <script>
  import { listShipments,getTemp } from "@/api/flee/productcode";
  
  export default {
    name: "Shipments",
    data() {
      return {
        // 遮罩层
        loading: true,
        // 选中数组
        ids: [],
        codes: [],
        // 非单个禁用
        single: true,
        // 非多个禁用
        multiple: true,
        // 显示搜索条件
        showSearch: true,
        // 总条数
        total: 0,
        // 出库表格数据
        shipmentsList: [],
        // 弹出层标题
        title: "",
        // 是否显示弹出层
        open: false,
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 10,
          shipmentsCode: null,
          shipmentsDate: null,
          starCode: null,
          endCode: null,
          agentCode: null,
          agentName: null,
          number: null,
          shipmentsUnit: null,
          materialCode: null,
          materialName: null
        },
        // 表单参数
        form: {
        },
        // 表单校验
        rules: {
          
        },
        // 代理商集合
        agentNames: [],
        // 产品集合
        materialNames: [],
        // 单位集合
        shipmentsUnits: [],
      };
    },
    created() {
    //   this.getList();
    this.getTemp();
    },
    methods: {
  
      getTemp(){
        getTemp().then(response => {
          this.shipmentsList = response.rows;
          this.loading = false;
        });
      },

      /** 查询出库列表 */
      getList() {
        this.loading = true;
        listShipments(this.queryParams).then(response => {
          this.shipmentsList = response.rows;
          this.total = response.total;
          this.loading = false;
        });
      },
      // 取消按钮
      cancel() {
        this.open = false;
        this.reset();
      },
      // 表单重置
      reset() {
        this.form = {
          shipmentsId: null,
          shipmentsCode: null,
          shipmentsDate: null,
          starCode: null,
          endCode: null,
          agentCode: null,
          agentName: null,
          number: null,
          shipmentsUnit: null,
          materialCode: null,
          materialName: null
        };
        this.resetForm("form");
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.pageNum = 1;
        if (this.queryParams.materialCode === null || this.queryParams.materialCode === ''){
            this.getTemp();
        }else{
            this.getList();
        }
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.resetForm("queryForm");
        this.getTemp();
        // this.handleQuery();
      },
      
    }
  };
  </script>
  